package com.dajie.pt.dao;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Component;

import com.dajie.common.util.StringUtil;
import com.dajie.pt.dao.base.BaseIbatisDao;
import com.dajie.pt.model.InvitationApply;

/**
 * InvitationApply DAO.
 */
@Component
public class InvitationApplyDao extends BaseIbatisDao<InvitationApply, Long>
{

	@Override
	protected Class getEntityClass()
	{
		return InvitationApply.class;
	}
	
	public int getCount()
	{
		return (Integer) db().queryForObject(this.getCountQuery(),map());
	}

	public InvitationApply getInvitationApplyInfoByUEJ(Integer uid,String email,String jid)
	{
		List<InvitationApply> iaList = this.getInvitationApplyByMap(this.map("uid",uid,"email",email,"jid",jid));
		return (iaList!=null && iaList.size()>0 )? iaList.get(0):null ;
	}
	
	public InvitationApply getInvitationApplyInfoByMobileAndUid(String mobile,Integer uid)
	{
		List<InvitationApply> iaList = this.getInvitationApplyByMap(this.map("mobile",mobile,"uid",uid));
		return (iaList!=null && iaList.size()>0 )? iaList.get(0):null ;
	}
	
	public List<InvitationApply> getInvitationApplyByMap(Map params)
	{
		return db().queryForList(this.getPageSelect(), params);
	}
	
	public int updateByUniqueKey(InvitationApply invitationInfo)
	{
		if(StringUtil.isNotEmpty(invitationInfo.getMobile()) && invitationInfo.getUid() != null)
		{
			return db().update("InvitationApply.updateByUniqueKey", invitationInfo);
		}else
		{
			return 0;
		}
	}
	
	public int saveApplyRecord(InvitationApply entity)
	{
		db().update("InvitationApply.insertApplyRecord", entity);
		return 1;
	}
	
	public String getIdsByMobile(String mobile)
	{
		return (String)db().queryForObject("InvitationApply.getIdsByMobile", mobile);
	}
	
	
	public List showlist(Map<String,Object> parmas)
	{
		return db().queryForList("InvitationApply.showlist", parmas);
	}
	
	public void saveCode(Map<String,Object> params)
	{
		db().update("InvitationApply.savecode", params);
	}
	
	public Object getCode(String mobile)
	{
		return db().queryForObject("InvitationApply.getcode", mobile);
	}
}